package mamikeji.liaowa.ui.activity.right;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

import mamikeji.liaowa.R;
import mamikeji.liaowa.ui.activity.BaseActivity;

public class CodeActivity extends BaseActivity {
    private WebView webView_code;
    private ProgressBar progressBar_code_details;
    private static final String TAG = "CodeActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_code);
        getBase();
        setTitleLeftBtn();

        String activity_code_url = getIntent().getStringExtra("activity_code_url");

        webView_code = (WebView) findViewById(R.id.webView_code);
        progressBar_code_details = (ProgressBar) findViewById(R.id.progressBar_code_details);

        WebSettings webSettings = webView_code.getSettings();

        // 设置WebView属性，能够执行JavaScript脚本
        webSettings.setJavaScriptEnabled(true);
        // 设置可以支持缩放
        webSettings.setSupportZoom(true);
        // 设置出现缩放工具
        webSettings.setBuiltInZoomControls(true);
        // 为图片添加放大缩小功能
        //webview.getSettings().setUseWideViewPort(true);
        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);

        webView_code.setHorizontalScrollBarEnabled(false);//禁止水平滚动
        webView_code.setVerticalScrollBarEnabled(true);//允许垂直滚动


        webView_code.loadUrl(activity_code_url);

        webView_code.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView_code.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 100) {
                    progressBar_code_details.setVisibility(View.GONE);//加载完网页进度条消失
                } else {
                    progressBar_code_details.setVisibility(View.VISIBLE);//开始加载网页时显示进度条
                    progressBar_code_details.setProgress(newProgress);//设置进度值
                }
            }

        });
    }

    @Override
    protected void onPause() {
        super.onPause();
        webView_code.onPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        webView_code.onResume();
    }
}
